home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CDsupport / aMiPEG / source / sjrevdct.s < prev    next >
Text File  |  1996-07-08  |  14KB  |  823 lines

  1. ;
  2. ; This code implements the basic idct on a 8x8 pixel block.
  3. ; Basically, it's the same as in the JPEG engine, with the sole difference
  4. ; that it's inlined and register-wise a little bit more optimized there.
  5. ;
  6. ; This is a complete rewrite in assembler. Heavy stuff. Lotsa work.
  7. ;
  8. ; Michael Rausch  14-4-94  1:14:00
  9. ;
  10.  
  11. ;
  12. ; The whole code handles D-Frames not very well, but I'll fix it on day.
  13. ;
  14.  
  15.  
  16. DCTSIZE    EQU    8
  17.  
  18. PASS1_BITS EQU    2
  19. CONST_BITS EQU    13
  20.  
  21.  
  22. FIX_0_298631336 EQU    2446    ;1    +    $98e    100110001110
  23. _FIX_0_390180644 EQU    -3196    ;2    -    $c7c
  24. FIX_0_541196100 EQU    4433    ;3    +    $1151    u
  25. FIX_0_765366865 EQU    6270    ;4    +    $187e    u
  26. _FIX_0_899976223 EQU    -7373    ;5    -    $1ccd
  27. FIX_1_175875602 EQU    9633    ;6    +    $25a1
  28. FIX_1_501321110 EQU    12299    ;7    +    $300b
  29. _FIX_1_847759065 EQU    -15137    ;8    -    $3b21    u
  30. _FIX_1_961570560 EQU    -16069    ;9    -    $3ec5
  31. FIX_2_053119869 EQU    16819    ;10    +    $41b3
  32. _FIX_2_562915447 EQU    -20995    ;11    -    $5203
  33. FIX_3_072711026 EQU    25172    ;12    +    $6254
  34.  
  35. ; FIX_1_847759065-FIX_0_765366865 = 2* FIX_0_541196100
  36.  
  37.  
  38. ; **************************************************************************
  39.  
  40. jrevdct:
  41.  
  42.     sub.w    #16,sp
  43.  
  44.     move.l    a0,-(sp)
  45.     lea    compose1(pc),a5
  46.     moveq    #DCTSIZE-1,d7
  47. idct1:    move.l    d7,-(sp)
  48.  
  49.     lea    2(a0),a1
  50.     move.l    (a1)+,d2
  51.     move.l    d2,d0
  52.     move.l    (a1)+,d4
  53.     move.l    (a1)+,d3
  54.     or.l    d4,d0
  55.     or.w    (a1)+,d0
  56.     or.l    d3,d0
  57.     bne.s    idct1_no_ac0
  58.     move.w    (a0),d0
  59.     lsl.w    #PASS1_BITS,d0
  60.     move.w    d0,d1
  61.     swap    d0
  62.     move.w    d1,d0
  63.     REPT    4
  64.     move.l    d0,(a0)+
  65.     ENDR
  66.     bra    idct1_next
  67. idct1_no_ac0:
  68.  
  69.     move.w    d2,d1            ; 2
  70.     add.w    d3,d1            ; 6
  71.     muls    #FIX_0_541196100,d1
  72.     muls    #_FIX_1_847759065,d3
  73.     add.l    d1,d3
  74.     muls    #FIX_0_765366865,d2
  75.     add.l    d1,d2
  76.  
  77.  
  78.     move.w    (a0),d0
  79.     ext.l    d0            ; 0
  80.     ext.l    d4            ; 4
  81.     move.l    d0,d5
  82.     sub.l    d4,d5
  83.     add.l    d0,d4
  84.  
  85.  
  86.     moveq    #CONST_BITS,d0
  87.     lsl.l    d0,d4
  88.     lsl.l    d0,d5
  89.  
  90. ;    lsl.l    #5,d4
  91. ;    lsl.l    #5,d5
  92. ;    addq.l    #1<<2,d4
  93. ;    addq.l    #1<<2,d5
  94. ;    lsl.l    #8,d4
  95. ;    lsl.l    #8,d5
  96.  
  97.     lea    12(sp),a1    ; top + 2 longs -> 16 bytes platz auf dem stack
  98.     move.l    d4,d0
  99.     add.l    d2,d4
  100.     move.l    d4,(a1)+    ; tmp10
  101.     sub.l    d2,d0
  102.     move.l    d5,d1
  103.     add.l    d3,d5
  104.     move.l    d5,(a1)+    ; tmp11
  105.     sub.l    d3,d1
  106.     move.l    d1,(a1)+    ; tmp12
  107.     move.l    d0,(a1)+    ; tmp13
  108.  
  109. odd_part1: 
  110.     move.w    7*2(a0),d1    ;7
  111.     beq    o0xxx
  112. o1xxx:    move.w    5*2(a0),d2    ;5
  113.     beq    o10xx
  114. o11xx:    move.w    3*2(a0),d3    ;3
  115.     beq    o110x
  116. o111x:    move.w    1*2(a0),d4    ;1
  117.     bne.s    odd1_1111
  118.  
  119.  
  120. ;    7531
  121. odd1_1110:
  122.     move.w    d2,d6
  123.     move.w    d1,d0
  124.     moveq    #0,d4
  125.     bra.s    abk_2
  126.  
  127. ;    7531
  128. odd1_1111:
  129.     move.w    d2,d6
  130.     add.w    d4,d6
  131.     move.w    d1,d0
  132.     add.w    d4,d0
  133.     muls    #FIX_1_501321110,d4
  134. abk_2:    move.w    d1,d5
  135.     add.w    d3,d5
  136.     move.w    d5,d7
  137.     add.w    d6,d7
  138.     muls    #FIX_1_175875602,d7
  139.     muls    #_FIX_1_961570560,d5
  140.     muls    #_FIX_0_390180644,d6
  141.      add.l    d7,d5
  142.     add.l    d7,d6
  143.     move.w    d2,d7
  144.     add.w    d3,d7
  145.  
  146.     ext.l    d1
  147.     asl.l    #8,d1
  148.     move.l    d1,a2
  149.     asl.l    #3,d1
  150.     add.l    a2,d1
  151.  
  152. ;    muls    #FIX_0_298631336,d1
  153.  
  154.     ext.l    d2
  155.     asl.l    #8,d2
  156.     asl.l    #6,d2
  157.  
  158. ;    muls    #FIX_2_053119869,d2
  159.  
  160.     ext.l    d3
  161.     asl.l    #8,d3
  162.     asl.l    #5,d3
  163.     move.l    d3,a2
  164.     asl.l    #1,d3
  165.     add.l    a2,d3
  166.  
  167. ;    muls    #FIX_3_072711026,d3
  168.  
  169.     neg.w    d0
  170.     ext.l    d0
  171.     asl.l    #8,d0
  172.     asl.l    #5,d0
  173.  
  174. ;    muls    #_FIX_0_899976223,d0
  175.  
  176.     neg.w    d7
  177.     ext.l    d7
  178.     asl.l    #8,d7
  179.     asl.l    #4,d7
  180.     move.l    d7,a2
  181.     asl.l    #2,d7
  182.     add.l    a2,d7
  183.  
  184. ;    muls    #_FIX_2_562915447,d7
  185.  
  186.     add.l    d0,d1
  187.     add.l    d7,d2
  188.     add.l    d5,d1
  189.     add.l    d6,d2
  190.     add.l    d3,d5
  191.     add.l    d4,d6
  192.     add.l    d7,d5
  193.     add.l    d0,d6
  194.     jmp    (a5)
  195.  
  196. o2110x:    move.w    1*DCTSIZE*2(a0),d4    ;1
  197.     bne.s    odd1_1101
  198.  
  199. ;    7531
  200. odd1_1100:
  201.     move.w    d2,d6
  202.     move.w    d1,d3
  203.     moveq    #0,d4
  204.     bra.s    abk_3
  205.  
  206. o110x:    move.w    1*2(a0),d4    ;1
  207.     beq.s    odd1_1100
  208.  
  209. ;    7531
  210. odd1_1101:
  211.     move.w    d2,d6
  212.     move.w    d1,d3
  213.     add.w    d4,d6
  214.     add.w    d4,d3
  215.     muls    #FIX_1_501321110,d4
  216. abk_3:
  217.     move.w    d1,d5
  218.     move.w    d5,d7
  219.     add.w    d6,d7
  220.     muls    #FIX_1_175875602,d7    
  221.     muls    #_FIX_1_961570560,d5
  222.     muls    #_FIX_0_390180644,d6
  223.      add.l    d7,d5
  224.     add.l    d7,d6
  225.     move.w    d2,d0
  226.     muls    #FIX_0_298631336,d1
  227.     muls    #FIX_2_053119869,d2
  228.     muls    #_FIX_0_899976223,d3
  229.     muls    #_FIX_2_562915447,d0
  230.     add.l    d3,d1
  231.     add.l    d0,d2
  232.     add.l    d5,d1
  233.     add.l    d6,d2
  234.     add.l    d4,d6
  235.     add.l    d0,d5
  236.     add.l    d3,d6
  237.     jmp    (a5)
  238.  
  239. o10xx:    move.w    3*2(a0),d3    ;3
  240.     beq    o100x
  241. o101x:    move.w    1*2(a0),d4    ;1
  242.     beq.s    odd1_1010
  243.  
  244. ;    7531
  245. odd1_1011:
  246.     move.w    d1,d5
  247.     add.w    d3,d5
  248.     move.w    d1,d0
  249.     move.w    d4,d6
  250.     add.w    d4,d0
  251.     muls    #FIX_1_501321110,d4
  252.     move.w    d5,d7
  253.     add.w    d6,d7
  254.     muls    #_FIX_0_390180644,d6
  255. abk_4:    muls    #FIX_1_175875602,d7
  256.     muls    #_FIX_1_961570560,d5
  257.     add.l    d7,d6
  258.      add.l    d7,d5
  259.     move.w    d3,d7
  260.     muls    #FIX_0_298631336,d1
  261.     muls    #FIX_3_072711026,d3
  262.     muls    #_FIX_0_899976223,d0
  263.     muls    #_FIX_2_562915447,d7
  264.     add.l    d0,d1
  265.     move.l    d6,d2
  266.     add.l    d5,d1
  267.     add.l    d7,d2
  268.     add.l    d3,d5
  269.     add.l    d4,d6
  270.     add.l    d7,d5
  271.     add.l    d0,d6
  272.     jmp    (a5)
  273.  
  274. o210xx:    move.w    3*DCTSIZE*2(a0),d3    ;3
  275.     beq    o2100x
  276. o2101x:    move.w    1*DCTSIZE*2(a0),d4    ;1
  277.     bne.s    odd1_1011
  278.  
  279. ;    7531
  280. odd1_1010:
  281.     move.w    d1,d5
  282.     add.w    d3,d5
  283.     move.w    d1,d0
  284.     moveq    #0,d4
  285.     move.w    d5,d7
  286.     moveq    #0,d6
  287.     bra.s    abk_4
  288.  
  289. o100x:    move.w    1*2(a0),d4    ;1
  290.     beq.s    odd1_1000
  291.  
  292. ;    7531
  293. odd1_1001:
  294.     move.w    d1,d0
  295.     add.w    d4,d0
  296.     move.w    d1,d5
  297.     move.w    d4,d6
  298.     move.w    d0,d7
  299.     muls    #FIX_1_175875602,d7
  300.     muls    #_FIX_1_961570560,d5
  301.     muls    #_FIX_0_390180644,d6
  302.      add.l    d7,d5
  303.     add.l    d7,d6
  304.     muls    #FIX_0_298631336,d1
  305.     muls    #FIX_1_501321110,d4
  306.     muls    #_FIX_0_899976223,d0
  307.     add.l    d0,d1
  308.     add.l    d5,d1
  309.     move.l    d6,d2
  310.     add.l    d4,d6
  311.     add.l    d0,d6
  312.     jmp    (a5)
  313.  
  314. o2100x:    move.w    1*DCTSIZE*2(a0),d4    ;1
  315.     bne.s    odd1_1001
  316.  
  317. ;    7531
  318. odd1_1000:
  319.     move.w    d1,d2
  320.     move.w    d1,d5
  321.     move.w    d1,d6
  322.     muls    #FIX_1_175875602,d2
  323.     muls    #FIX_1_175875602+_FIX_0_899976223,d6
  324.     muls    #FIX_1_175875602+_FIX_1_961570560,d5
  325.     muls    #FIX_1_175875602+_FIX_0_899976223+_FIX_1_961570560+FIX_0_298631336,d1
  326.     jmp    (a5)
  327.  
  328.  
  329. o0xxx:    move.w    5*2(a0),d2    ;5
  330.     beq    o00xx
  331. o01xx:    move.w    3*2(a0),d3    ;3
  332.     beq    o010x
  333. o011x:    move.w    1*2(a0),d4    ;1
  334.     beq.s    odd1_0110
  335.  
  336. ;    7531
  337. odd1_0111:    ; opt8
  338.     move.w    d2,d6
  339.     add.w    d4,d6
  340.     move.w    d4,d1
  341.     muls    #FIX_1_501321110,d4
  342.     muls    #_FIX_0_899976223,d1
  343. abk_1:    move.w    d2,d0
  344.     add.w    d3,d0
  345.     move.w    d3,d5
  346.  
  347.     move.w    d5,d7
  348.     add.w    d6,d7
  349.     muls    #FIX_1_175875602,d7
  350.     muls    #_FIX_1_961570560,d5
  351.     muls    #_FIX_0_390180644,d6                ; ???? 2
  352.      add.l    d7,d5
  353.     add.l    d7,d6
  354.  
  355.     muls    #FIX_2_053119869,d2
  356.     muls    #FIX_3_072711026,d3
  357.     muls    #_FIX_2_562915447,d0
  358.     add.l    d0,d2
  359.     add.l    d6,d2
  360.     add.l    d4,d6
  361.     add.l    d1,d6
  362.     add.l    d5,d1
  363.     add.l    d3,d5
  364.     add.l    d0,d5
  365.     jmp    (a5)
  366.  
  367. o20xxx:    move.w    5*DCTSIZE*2(a0),d2    ;5
  368.     beq    o200xx
  369. o201xx:    move.w    3*DCTSIZE*2(a0),d3    ;3
  370.     beq.s    o2010x
  371. o2011x:    move.w    1*DCTSIZE*2(a0),d4    ;1
  372.     bne.s    odd1_0111
  373.  
  374. ;    7531
  375. odd1_0110:
  376.     move.w    d2,d6
  377.     moveq.l    #0,d1
  378.     moveq.l    #0,d4
  379.     bra.s    abk_1
  380.  
  381. o010x:    move.w    1*2(a0),d4    ;1
  382.     beq.s    odd1_0100
  383.  
  384. ;    7531
  385. odd1_0101:
  386.     move.w    d2,d6
  387.     move.w    d2,d7
  388.     add.w    d4,d6
  389.     move.w    d4,d1
  390.     move.w    d6,d5
  391.     muls    #FIX_1_175875602,d5
  392.     muls    #_FIX_0_390180644+FIX_1_175875602,d6
  393.     muls    #FIX_2_053119869+_FIX_2_562915447,d2
  394.     muls    #FIX_1_501321110,d4
  395.     muls    #_FIX_0_899976223,d1
  396.     muls    #_FIX_2_562915447,d7
  397.     add.l    d6,d2
  398.     add.l    d1,d6
  399.     add.l    d5,d1
  400.     add.l    d7,d5
  401.     add.l    d4,d6
  402.     jmp    (a5)
  403.  
  404. o2010x:    move.w    1*DCTSIZE*2(a0),d4    ;1
  405.     bne.s    odd1_0101
  406.  
  407. ;    7531
  408. odd1_0100:
  409.     move.w    d2,d6
  410.     move.w    d2,d1
  411.     move.w    d2,d5
  412.     muls    #FIX_1_175875602,d1
  413.     muls    #FIX_1_175875602+_FIX_2_562915447,d5
  414.     muls    #FIX_1_175875602+_FIX_0_390180644,d6
  415.     muls    #FIX_1_175875602+_FIX_2_562915447+_FIX_0_390180644+FIX_2_053119869,d2
  416.     jmp    (a5)
  417.  
  418. o00xx:    move.w    3*2(a0),d5    ;3
  419.     beq.s    o000x
  420. o001x:    move.w    1*2(a0),d4    ;1
  421.     beq.s    odd1_0010
  422.  
  423. ;    7531
  424. odd1_0011:    ; opt12
  425.     move.w    d5,d2
  426.     move.w    d5,d3
  427.     move.w    d4,d1
  428.     move.w    d4,d6
  429.     move.w    d3,d7
  430.     add.w    d4,d7
  431.     muls    #FIX_1_175875602,d7
  432.     muls    #_FIX_1_961570560,d5
  433.     muls    #_FIX_0_390180644,d6
  434.      add.l    d7,d5
  435.     add.l    d7,d6
  436.     muls    #_FIX_2_562915447+FIX_3_072711026,d3
  437.     muls    #_FIX_0_899976223+FIX_1_501321110,d4
  438.     muls    #_FIX_0_899976223,d1
  439.     muls    #_FIX_2_562915447,d2
  440.     add.l    d5,d1
  441.     add.l    d6,d2
  442.     add.l    d3,d5
  443.     add.l    d4,d6
  444.     jmp    (a5)
  445.  
  446. o200xx:    move.w    3*DCTSIZE*2(a0),d5    ;3
  447.     beq    o2000x
  448. o2001x:    move.w    1*DCTSIZE*2(a0),d4    ;1
  449.     bne.s    odd1_0011
  450.  
  451. ;    7531
  452. odd1_0010:
  453.     move.w    d5,d6
  454.     move.w    d5,d2
  455.     muls    #FIX_1_175875602,d6
  456.     move.w    d5,d1
  457.     muls    #FIX_1_175875602+_FIX_2_562915447,d2
  458.     muls    #FIX_1_175875602+_FIX_1_961570560,d1
  459.     muls    #FIX_1_175875602+_FIX_2_562915447+_FIX_1_961570560+FIX_3_072711026,d5
  460.     jmp    (a5)
  461.  
  462. o000x:    move.w    1*2(a0),d6    ;1
  463.     beq.s    odd1_0000
  464.  
  465. ;    7531
  466. odd1_0001:    ; opt 14
  467.     move.w    d6,d5
  468.     move.w    d6,d1
  469.     muls    #FIX_1_175875602,d5
  470.     move.w    d6,d2
  471.     muls    #FIX_1_175875602+_FIX_0_899976223,d1
  472.     muls    #FIX_1_175875602+_FIX_0_390180644,d2
  473.     muls    #FIX_1_175875602+_FIX_0_899976223+_FIX_0_390180644+FIX_1_501321110,d6
  474.     jmp    (a5)
  475.  
  476. ; priority: 14 12 8 0 
  477.  
  478. ;    7531
  479. odd1_0000:
  480.     moveq    #CONST_BITS-PASS1_BITS,d7    ; optimized compose !
  481.  
  482.     lea    12(sp),a1
  483.     move.l    (a1)+,d0    ; tmp10
  484.     lsl.l    #16-(CONST_BITS-PASS1_BITS),d0
  485.     move.l    (a1)+,d1    ; tmp11
  486.     lsr.l    d7,d1
  487.     move.w    d1,d0
  488.  
  489.     move.l    (a1)+,d2    ; tmp12
  490.     lsl.l    #16-(CONST_BITS-PASS1_BITS),d2
  491.     move.l    (a1)+,d3    ; tmp13
  492.     lsr.l    d7,d3
  493.     move.w    d3,d2
  494.  
  495.     move.l    d0,(a0)+
  496.     swap    d0
  497.     move.l    d2,(a0)+
  498.     swap    d2
  499.     move.l    d2,(a0)+
  500.     move.l    d0,(a0)+
  501.  
  502.     move.l    (sp)+,d7
  503.     dbra    d7,idct1
  504.     bra.s    idct1_ready
  505.  
  506. ; keep 1 2 5 6
  507.  
  508. compose1: moveq    #CONST_BITS-PASS1_BITS,d7
  509.  
  510.     lea    12(sp),a1
  511.     move.l    (a1)+,d4    ; tmp10
  512.     sub.l    d6,d4
  513.     add.l    d6,d6
  514.     add.l    d4,d6
  515.     lsl.l    #16-(CONST_BITS-PASS1_BITS),d6
  516.     move.l    (a1)+,d3    ; tmp11
  517.     sub.l    d5,d3
  518.     add.l    d5,d5
  519.     add.l    d3,d5
  520.     lsr.l    d7,d5
  521.     move.w    d5,d6
  522.     move.l    d6,(a0)+
  523.     move.l    (a1)+,d6    ; tmp12
  524.     sub.l    d2,d6
  525.     add.l    d2,d2
  526.     add.l    d6,d2
  527.     lsl.l    #16-(CONST_BITS-PASS1_BITS),d2
  528.     move.l    (a1)+,d5    ; tmp13
  529.     sub.l    d1,d5
  530.     add.l    d1,d1
  531.     add.l    d5,d1
  532.     lsr.l    d7,d1
  533.     move.w    d1,d2
  534.     move.l    d2,(a0)+
  535.     lsl.l    #16-(CONST_BITS-PASS1_BITS),d5
  536.     lsr.l    d7,d6
  537.     move.w    d6,d5
  538.     move.l    d5,(A0)+
  539.     lsl.l    #16-(CONST_BITS-PASS1_BITS),d3
  540.     lsr.l    d7,d4
  541.     move.w    d4,d3
  542.     move.l    d3,(a0)+
  543.  
  544. idct1_next:
  545.     move.l    (sp)+,d7
  546.     dbra    d7,idct1
  547.  
  548. idct1_ready:
  549. ; *******************************************************
  550.  
  551.     move.l    (sp)+,a0
  552.     lea    compose2(pc),a5
  553.     moveq    #DCTSIZE-1,d7
  554. idct2:    move.l    d7,-(sp)
  555.  
  556.  
  557. odd_part2: 
  558.     move.w    7*DCTSIZE*2(a0),d1    ;7
  559.     beq    o20xxx
  560. o21xxx:    move.w    5*DCTSIZE*2(a0),d2    ;5
  561.     beq    o210xx
  562. o211xx:    move.w    3*DCTSIZE*2(a0),d3    ;3
  563.     beq    o2110x
  564. o2111x:    move.w    1*DCTSIZE*2(a0),d4    ;1
  565.     beq    odd1_1110
  566.     bra    odd1_1111
  567.  
  568. o2000x:    move.w    1*DCTSIZE*2(a0),d6    ;1
  569.     bne    odd1_0001
  570.  
  571. odd0_0000:
  572.     move.w    2*DCTSIZE*2(a0),d2
  573.     move.w    4*DCTSIZE*2(a0),d4
  574.     move.w    6*DCTSIZE*2(a0),d3
  575.     move.w    d2,d0
  576.     add.w    d3,d0
  577.     muls    #FIX_0_541196100/4,d0
  578.     muls    #_FIX_1_847759065/4,d3
  579.     add.l    d0,d3
  580.     muls    #FIX_0_765366865/4,d2
  581.     add.l    d0,d2
  582.  
  583.     move.w    (a0),d0
  584.     add.w    #1<<(PASS1_BITS+3-1),d0        ; precalc from the descaling part below
  585.     ext.l    d4
  586.     ext.l    d0
  587.     move.l    d0,d5
  588.     sub.l    d4,d5
  589.     add.l    d0,d4
  590.  
  591.     moveq    #CONST_BITS-2,d0
  592.     lsl.l    d0,d4
  593.     lsl.l    d0,d5
  594.  
  595.     move.l    d4,d0
  596.     add.l    d2,d4
  597.     swap     d4
  598.     move.w    d4,(a0)+
  599.     sub.l    d2,d0
  600.     move.w    d4,7*DCTSIZE*2-2(a0)
  601.     swap    d0
  602.     move.w    d0,3*DCTSIZE*2-2(a0)
  603.     move.l    d5,d4
  604.     move.w    d0,4*DCTSIZE*2-2(a0)
  605.     add.l    d3,d5
  606.     swap     d5
  607.     sub.l    d3,d4
  608.     move.w    d5,1*DCTSIZE*2-2(a0)
  609.     swap    d4
  610.     move.w    d5,6*DCTSIZE*2-2(a0)
  611.     move.w    d4,2*DCTSIZE*2-2(a0)
  612.     move.w    d4,5*DCTSIZE*2-2(a0)
  613.  
  614.     move.l    (sp)+,d7
  615.     dbra    d7,idct2
  616.     bra    idct2_ready
  617.  
  618.  
  619. compose2:
  620.     move.w    2*DCTSIZE*2(a0),d3
  621.     move.w    4*DCTSIZE*2(a0),d4
  622.     move.w    6*DCTSIZE*2(a0),d7
  623.  
  624.     move.w    d3,d0
  625.     add.w    d7,d0
  626.     muls    #FIX_0_541196100,d0
  627.     muls    #_FIX_1_847759065,d7
  628.     add.l    d0,d7
  629.     muls    #FIX_0_765366865,d3
  630.     add.l    d0,d3
  631.  
  632.     asr.l    #2,d7
  633.     asr.l    #2,d3
  634.     move.l    d7,a3
  635.  
  636.     move.w    (a0),d0
  637.     add.w    #1<<(PASS1_BITS+3-1),d0    ; precalc from the descaling part below
  638.     ext.l    d4
  639.     ext.l    d0
  640.     move.l    d0,d7
  641.     sub.l    d4,d7
  642.     add.l    d0,d4
  643.  
  644.     moveq    #CONST_BITS-2,d0
  645.     lsl.l    d0,d4
  646.     lsl.l    d0,d7
  647.  
  648.  
  649.     asr.l    #2,d6
  650.     asr.l    #2,d5
  651.     asr.l    #2,d2
  652.     asr.l    #2,d1
  653.  
  654.  
  655.     move.l    d4,d0
  656.     add.l    d3,d4
  657.     sub.l    d3,d0
  658.  
  659.     move.l    d7,d3
  660.     add.l    a3,d7
  661.     sub.l    a3,d3
  662.  
  663.  
  664.     sub.l    d6,d4
  665.     add.l    d6,d6
  666.     add.l    d4,d6
  667.  
  668.     swap    d6                ; moveq    #CONST_BITS+PASS1_BITS+3  -2   ,d6   ;   asr.l d6,d3
  669.     move.w    d6,(a0)+
  670.     swap    d4
  671.     move.w    d4,7*DCTSIZE*2-2(a0)
  672.  
  673.     sub.l    d1,d0
  674.     add.l    d1,d1
  675.     add.l    d0,d1
  676.  
  677.     swap    d1
  678.     move.w    d1,3*DCTSIZE*2-2(a0)
  679.     swap    d0
  680.     move.w    d0,4*DCTSIZE*2-2(a0)
  681.  
  682.     sub.l    d5,d7
  683.     add.l    d5,d5
  684.     add.l    d7,d5
  685.  
  686.     swap    d5
  687.     move.w    d5,1*DCTSIZE*2-2(a0)
  688.     swap    d7
  689.     move.w    d7,6*DCTSIZE*2-2(a0)
  690.  
  691.     sub.l    d2,d3
  692.     add.l    d2,d2
  693.     add.l    d3,d2
  694.  
  695.     swap    d2
  696.     move.w    d2,2*DCTSIZE*2-2(a0)
  697.     swap    d3
  698.     move.w    d3,5*DCTSIZE*2-2(a0)
  699.  
  700. idct2_next:
  701.     move.l    (sp)+,d7
  702.     dbra    d7,idct2
  703.  
  704. idct2_ready;
  705.     add.w    #16,sp
  706. ;    movem.l    (sp)+,JREVDCTREGS
  707.  
  708.     movem.l    (sp)+,ri_regs
  709.     rts
  710.  
  711.  
  712.     XDEF    @j_rev_dct
  713. @j_rev_dct:
  714.     movem.l    ri_regs,-(sp)
  715.     bra    jrevdct
  716.  
  717.  
  718.     ifeq    1
  719. ; **************************************************************************
  720.  
  721. ; Pre compute singleton coefficient IDCT values.
  722. ;
  723. ; void init_pre_idct(void)
  724.  
  725. ;    XDEF @init_pre_idct
  726. @init_pre_idct:
  727.     movem.l    d2/a2,-(sp)
  728.  
  729.     lea    PreIDCT,a2
  730.     move.w    #64*64/4/4-1,d2
  731. preidctclr:
  732.     clr.l    (a2)+
  733.     clr.l    (a2)+
  734.     clr.l    (a2)+
  735.     clr.l    (a2)+
  736.     dbra    d2,preidctclr
  737.  
  738.     lea    PreIDCT+63*64*2,a2
  739.     moveq    #63,d2
  740. preidctloop:
  741.     move.w    #2048,(a2,d2.w)
  742.     move.l    a2,a0
  743.     bsr    @j_rev_dct
  744.     sub.w    #64,a2
  745.     dbra    d2,preidctloop
  746.  
  747.     movem.l    (sp)+,d2/a2
  748.     rts
  749.  
  750. ; ************************************************************************************
  751.  
  752. ; Perform the inverse DCT on one block of coefficients.
  753. ;
  754. ; void j_rev_dct_sparse (DCTBLOCK data, int pos)  
  755.  
  756. ;    XDEF    @j_rev_dct_sparse
  757. @j_rev_dct_sparse:
  758.  
  759.     tst.l    d0
  760.     bne    itsnotthedc
  761.  
  762. ; the single element to cope with is the dc coefficient
  763.  
  764.     move.w    (a0),d1
  765.     bpl.s    scale_dc
  766.     subq.w    #3+4,d1                ; "implement" the rounding error
  767. scale_dc:addq.w    #4,d1
  768.     asr.w    #3,d1
  769.  
  770.     move.w    d1,d0                ; extend to longword
  771.     swap    d0
  772.     move.w    d1,d0
  773.  
  774.     moveq    #7,d1
  775. set_dc:    move.l    d0,(a0)+
  776.     move.l    d0,(a0)+
  777.     move.l    d0,(a0)+
  778.     move.l    d0,(a0)+
  779.     dbra    d1,set_dc
  780.  
  781.     rts                    ; not that pretty
  782. ;    bra    exit_jrds
  783. itsnotthedc:
  784.     movem.l    d2/d3,-(sp)
  785.  
  786. ; Some other coefficient. 
  787.  
  788.     move.w    (a0,d0.w),d1        ; get coeff
  789.  
  790.     lea    PreIDCT,a1        ; get precalculated DCT
  791.     lsl.l    #7,d0
  792.     add.l    d0,a1
  793.  
  794.     moveq    #CONST_BITS-PASS1_BITS-8,d3    ; scale down
  795.  
  796.     moveq.l    #31,d0
  797. set_ac:    move.w    d1,d2
  798.     muls    (a1)+,d2
  799.     lsr.l    d3,d2
  800.     move.w    d2,(a0)+
  801.     move.w    d1,d2
  802.     muls    (a1)+,d2
  803.     lsr.l    d3,d2
  804.     move.w    d2,(a0)+
  805.     dbra    d0,set_ac
  806.  
  807.     movem.l    (sp)+,d2/d3
  808. exit_jrds: rts
  809.  
  810. ; ************************************************************************************
  811.  
  812.     section bss,BSS
  813.  
  814. ;
  815. ; Precomputed idct value arrays
  816. ;
  817. PreIDCT: ds.w    64*64
  818.  
  819.     endc
  820.  
  821.  
  822. ;    END
  823.